<script setup>
import { ref, reactive, getCurrentInstance, onMounted, watch, nextTick } from "vue"
import moment from "moment"

const instance = getCurrentInstance()
const _this = instance.appContext.config.globalProperties //vue3获取当前this
const storage = _this.$utils.storage;

import { globalStore } from "@/store/global";
const globalVue = globalStore();

const {prodUrl} = window.global_API;

// 组件中使用，接收传参的
let propsData = defineProps({
  data: {
    type: Object,
    required: true
  },
  defaultContent: {
    type: Boolean,
    default: false
  }
})
// 组件中使用，接收事件的
const emits = defineEmits(['submit']);

const alarmVideo = ref(null);
const notVideo = ref(true);

let once = true;

onMounted(() => {
  console.log(globalVue.isTourist);
  alarmVideo.value.addEventListener("error",function(e){
    console.log('视频报错，--------------', e);
    if (once) {
      once = false;
      setTimeout(() => {
        alarmVideo.value.load();
      }, 3000);
    }else{
      notVideo.value = false;
    }
  },false);

})

const handleAlarmForm = reactive({})

function handleAlarmSubmit(){
	handleAlarmForm['id'] = propsData.data.id;
  emits('submit', handleAlarmForm);
}

</script>
<template>
  <div class="notification_box">
    <div class="box_video">
      <!-- <video autoplay controls loop src="https://prod-streaming-video-msn-com.akamaized.net/278b1c4f-3545-422c-9d56-242f18adadc9/2e3d6097-b233-40af-88f4-a90a74a33fa0.mp4"></video> -->
      <video ref="alarmVideo" v-show="notVideo" :src="prodUrl + 'file' + (data.videoPath || data.obsPath)" autoplay controls loop ></video>
      <div class="replay" v-show="notVideo">
        <span>Playback</span>
        <img src="@/assets/image/index/ico_playback.png" alt="">
      </div>
      <img class="notImage" v-show="!notVideo" src="@/assets/image/index/cio_no_signal.png" alt="">
    </div>
    <div class="box_info">
      <div class="alarm_title">
        <img :src="data.alarmImg" alt="">
        <div class="alarm_title_txt">
          <div class="f16" :style="{color: data.backgroundColor}">{{data.stateName}}</div>
          <div>{{data.classification}} | <div :class="data.status == 0 ? 'not_with' : 'yes_with'">{{ data.status == 0 ? 'untreated' : 'processed' }}</div>  </div>
        </div>
      </div>
      <div class="box_line"></div>
      <div class="marBom6">
        <span>Time：</span>
        <span>{{ moment(data.time).format('yyyy-MM-DD HH:mm:ss') }}</span>
      </div>
      <div class="marBom6">
        <span>Location：</span>
        <span>{{data.lng }}，{{ data.lat }}</span>
      </div>
      <div class="marBom6">
        <span>Vehicle：</span>
        <span>{{data.codenumber }}{{ (data.codenumber && data.carnumber) ?  ` ｜ ` : '' }}{{data.carnumber }}</span>
      </div>
      <div class="marBom6" v-if="data.status == 1">
        <span>Processed by：</span>
        <span>{{data.processBy }}</span>
      </div>
      <div class="marBom6" v-if="data.status == 1">
        <span>Handle Content：</span>
      </div>
      <div v-if="data.status == 1" class="hand_content">{{data.handleContent }}</div>
      <div class="box_form" v-if="data.status == 0">
        <div>Handling Content：</div>
      </div>
      <div v-if="data.status == 0" style="margin-top: 4px;"><el-input class="box_input" show-word-limit :rows="1.5" :maxlength="200" type="textarea" placeholder="Please enter handling content" v-model="handleAlarmForm.handleContent"></el-input></div>
      <div class="box_operate" v-if="data.status == 0">
        <el-button class="box_btn" type="primary" :disabled="!globalVue.isTourist" size="small" @click="handleAlarmSubmit">Confirm</el-button>	
      </div>
    </div>
  </div>
</template>
<style lang="less">
.box_info{
  .el-textarea__inner::placeholder{
    font-size: 12px;
  }
}
</style>
<style scoped lang="less">
.notification_box{
	display: flex;
	font-size: 12px;
	color: var(--mw-font-color-content);
  position: relative;
  // height: 330px;
  
  .txt_Phone{
    color: #FB393C;
    background-color: transparent;
  }
  .txt_Smoke{
    color: #F8780B;
    background-color: transparent;
  }
  .txt_Wheelchair{
    color: #E0AA26;
    background-color: transparent;
  }
  .hand_content{
    height: 42px;
    overflow: auto;
    line-height: 1.5;
  }
  .notification_btn{
    text-align: right;
  }
	.box_info{
		// width: 280px;
		padding: 0 5px 0 15px;
    flex: 1;
		.marBom6{
			margin-bottom: 0px;
      display: flex;
      justify-content: space-between;
      line-height: 1.5;
      span{
        display: inline-block;
        // width: 100px;
      }
		}
		.box_line{
			width: 100%;
			height: 1px;
			background-color: #D3D5D6;
			margin: 5px 0;
		}
		.alarm_title{
			display: flex;
			.alarm_title_txt{
				.f16{
					font-size: 16px;
				}
				span{
					background-color: rgb(252 58 155 / 10%);
					line-height: 20px;
					padding: 0 10px;
					border-radius: 99999px;
					color: rgb(252 58 155 / 100%);
				}
			}
			img{
				width: 38px;
				height: 38px;
				margin-right: 10px;
			}
		}
	}
	.box_video{
		width: 342px;
    position: relative;
    // border-radius: 2px;
    // background-color: #EDF0F4;
    .replay{
      position: absolute;
      right: 16px;
      bottom: 16px;
      display: flex;
      align-items: center;
      font-size: 12px;
      background-color: rgba(0, 178, 141, 0.5);
      border-radius: 99999px;
      height: 24px;
      padding: 0 10px;
      color: #ffffff;
      img{
        width: 20px;
        height: 20px;
        margin-left: 4px;
      }
    }
    .notImage{
      width: 163px;
      height: 146px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
    video{
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
			width: 100%;
			height: 100%;
			border-radius: 6px;
    }
	}
}
.box_operate{
  text-align: right;
  margin-top: 2px;
}
.box_form{
  display: flex;
  // margin-top: 10px;
  font-size: 12px;  
  line-height: 18px;
  .box_label{
    width: fit-content;
    margin: 4px 6px 0 0;
    font-size: 12px;
  }
  .box_input{
    flex: 1;
  }
}
</style>